package datastructure.queue;

import java.util.Random;

public class QueueTest {
    public static void main(String[] args) {

        System.out.println(19%20);

        // 定义测试数据量
        int loopCount = 1000000;

        // ArrayQueue<Integer> arrQueue = new ArrayQueue<>();
        // double time = queueTime(arrQueue, loopCount);
        // System.out.println("ArrayQueue:" + time + "s");

        LoopQueue<Integer> loopQueue = new LoopQueue<>();
        double time2 = queueTime(loopQueue, loopCount);
        System.out.println("LoopQueue:" + time2 + "s");

        LinkedListQueue<Integer> linkedListQueue = new LinkedListQueue<>();
        double time3 = queueTime(linkedListQueue, loopCount);
        System.out.println("linkedListQueue:" + time3 + "s");
    }

    public static double queueTime(Queue<Integer> queue, int loopCount) {

        long startTime = System.nanoTime();// 纳秒计算

        Random random = new Random();
        // 这里是入队操作,和出队操作,将进行对列和循环对列时间复杂度的比较
        for (int i = 0; i < loopCount; i++) {
            int value = random.nextInt(Integer.MAX_VALUE);
            queue.enqueue(value);
        }

        // 出队
        for (int i = 0; i < loopCount; i++) {
            queue.dequeue();
        }
        long endTime = System.nanoTime();

        return (endTime - startTime) / 1000000000.0;
    }

}
